package com.travel.mapper.order;
import com.travel.model.entity.service.Booking;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;
//订单mapper 查询订单 插入订单 
@Mapper
@Repository("bookingMapperMyBatis")
public interface BookingMapper {
    
    @Select("SELECT * FROM bookings WHERE user_id = #{userId}")
    List<Booking> findByUserId(@Param("userId") Long userId);
    
    @Select("SELECT * FROM bookings WHERE id = #{id}")
    @Results({
        @Result(property = "user", column = "user_id", 
            one = @One(select = "com.travel.mapper.user.UserMapper.findById")),
        @Result(property = "service", column = "service_id", 
            one = @One(select = "com.travel.mapper.service.ServiceMapper.findById"))
    })
    Optional<Booking> findById(@Param("id") Long id);
    
    @Insert("INSERT INTO bookings (user_id, service_id, booking_date, status, amount, created_time, update_time) " +
           "VALUES (#{user.id}, #{service.id}, #{bookingDate}, #{status}, #{amount}, #{createdTime}, #{updateTime})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void save(Booking booking);
    
    @Delete("DELETE FROM bookings WHERE id = #{id}")
    int delete(Booking booking);
} 